<template>
  <div>
    <!-- 查询框 -->
    <el-form :inline="true" :model="queryForm" class="demo-form-inline">

      <el-form-item label="title">
        <el-input v-model="queryForm.title" placeholder="title" clearable></el-input>
      </el-form-item>
      <el-form-item label="位置" clearable="">
        <el-input v-model="queryForm.detailItem" placeholder="位置" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="querySubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table
        :data="tableData"
        @selection-change="handleSelectionChange"
        style="width: 90%">
      <!-- 多选
      <el-table-column
      type="selection"
      ></el-table-column>-->

      <el-table-column width="100"
          label="#" prop="id"
      ></el-table-column>

      <el-table-column
          prop="title"
          label="标题">
      </el-table-column>

      <el-table-column label="Img" prop="elevator" width="50">
        <template slot-scope="scope">
          <img :src="scope.row.img" width="50px;">
        </template>
      </el-table-column>

      <el-table-column
          prop="detailItem"
          label="detailItem">
      </el-table-column>

      <el-table-column
          prop="detailItemTag"
          label="detailItemTag">
      </el-table-column>

      <el-table-column
                       prop="price"
                       label="price">
      </el-table-column>

      <el-table-column
                       prop="detailItemBotTag"
                       label="detailItemBotTag">
      </el-table-column>




    </el-table>

    <el-pagination
        :page-count="pageCount"
        :current-page="queryForm.current"
        @current-change="gotoPage"
        layout="prev, pager, next">
    </el-pagination>

    <div>
      <!-- <el-button size="mini" type="danger" @click="batchDel()">批删</el-button> -->
      <el-button size="mini" @click="spider()">房源抓取</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
      //查询条件
      queryForm:{
        pageNum:1,
        pageSize:6,
        detailItem: null,
        title: null
      },
      //列表数据
      tableData:[],
      //table选择数据Id数组
      selecteIds:[],
      //总页数
      pageCount:1,
      dialogVisible:false,
      form:{},
      houseTypeList:[
      {code:'jiZhShi', name: '集中式'},
      {code:'fenSanShi', name: '分散式'},
    ]
    }
  },
  methods:{
    spider() {
      this.axios.get("house-anjuke/spider").then(res=>{
        this.$message.success("开始抓取数据");
      })
    },
    save(){
      //ajax提交房源信息
      this.axios.post("house/save",this.form).then(res=>{
        if(res.data.result){
          //关闭对话框
          this.form={};
          this.dialogVisible = false;
          this.$message({
            message:"添加成功",
            type:"success"
          });
          this.querySubmit();
        }else {
          this.$message(res.data.message);
        }
      })
    },
    add(){
      this.$router.push("/update");
    },
    edit(row){
      this.$router.push("/update?id=" + row.houseId);
    },
    handleSelectionChange(rows){
      console.log(rows);
      //let ids = rows.map(function(row){return row.id});
      let ids = rows.map(row=>{return row.id});
      this.selecteIds = ids;
      console.log("selecteIds:"+this.selecteIds);
    },
    gotoPage(current){
      this.queryForm.pageNum = current;
      this.list();
    },
    querySubmit(){
      //发送ajax请求，根据queryForm查询数据
      console.log(this.queryForm);
      this.queryForm.pageNum=1;
      this.list();

    },
    //列表页数据
    list(){
      this.axios.get("house-anjuke/page",{params:this.queryForm}).then(res=>{
        this.tableData = res.data.data.list;
        this.pageCount = res.data.data.pages;
        this.queryForm.current = res.data.data.pageNum;
      })
    }
  },
  created(){
    this.list();
  }
}
</script>

<style scoped>

</style>
